package com.eyalsh.data_structures.linkedLists.basic;

/**
 * @author Eyal Shalev
 *
 */
public class DoublyLinkedList<T> extends LinkedList<T> implements com.eyalsh.data_structures.linkedLists.DoublyLinkedList<T> {
	
	private DoublyLinkedListNode<T> tail;
	
	@Override
	public DoublyLinkedListNode<T> tail() {
		return tail;
	}
	
	private void tail(DoublyLinkedListNode<T> value) {
		tail = value;
	}
	
	public void insertTail(T data) {
		DoublyLinkedListNode<T> temp = tail();
		tail(new DoublyLinkedListNode<T>(data, this));
		tail().previous(temp);
		if (temp != null)
			temp.next(tail());
	}

	@Override
	public void insertHead(T data) {
		DoublyLinkedListNode<T> temp = head();
		head(new DoublyLinkedListNode<T>(data, this));
		head().next(temp);
		if (temp != null)
			temp.previous(head());
	}

	@Override
	public DoublyLinkedListNode<T> head() {
		return (DoublyLinkedListNode<T>) super.head();
	}

}
